import UnityEngine

class Movement(MonoBehaviour):
    public turnspeed as single = 100
    public movespeed as single = 10
    
    public planar as Vector2
    public turn as single
    
    def FixedUpdate():
        transform.eulerAngles.y += turn * Time.fixedDeltaTime * turnspeed
        
        addp = Vector3(planar.x, 0, planar.y).normalized * movespeed
        
        # transform.position += transform.TransformDirection(addp)
        GetComponent(CharacterController).SimpleMove(transform.TransformDirection(addp) )
    
    [RPC]
    def UpdateMovement(planar as Vector3, info as NetworkMessageInfo):
        # if info.sender != Network.player:
        #     Debug.Log(["update", info.sender])
        move = GetComponent(Movement)
        move.planar = Vector2(planar.x, planar.y)
        move.turn = planar.z
    
    def OnSerializeNetworkView(stream as BitStream, info as NetworkMessageInfo):
        dir as Vector3
        
        if stream.isWriting:
            dir = Vector3(planar.x, planar.y, turn)
            stream.Serialize(dir)
        else:
            stream.Serialize(dir)
            planar = Vector2(dir.x, dir.y)
            turn = dir.z
    
